define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'balance/index' + location.search,
                    del_url: 'balance/del',
                    multi_url: 'balance/multi',
                    table: 'user_balance_log',
                    import_url: 'balance/import',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        {field: 'user.mobile', title: __('User.mobile')},
                        {field: 'user_id', title: __('User_id')},
                        // {field: 'to_user_id', title: __('转账ID')},
                        {field: 'amount', title: __('Amount'), formatter: function (value,row) {
                            if (row.type == 1) {
                                return '<span class="text-success">+'+row.amount+'</span>';
                            }else{
                                return '<span class="text-danger">-'+row.amount+'</span>';
                            }
                            //return row['log_type'] == 1?'+'.row['amount']:'-'.row['amount'];
                           }
                        },
                        {field: 'before', title: __('Before'), operate:'BETWEEN'},
                        {field: 'after', title: __('After'), operate:'BETWEEN'},
                        // {field: 'remark', title: __('Remark')},
                        // {field: 'admin_remark', title: '后台查看备注'},
                        // {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"0":__('Type 0')}, formatter: Table.api.formatter.normal},
                        {field: 'log_type', title: __('Log_type'), searchList: {"1":__('Log_type 1'),"2":__('Log_type 2'),"3":__('Log_type 3')}, formatter: Table.api.formatter.normal},
                        {field: 'source', title: __('Source'), searchList: {"1":__('Source 1'),"2":__('Source 2'),"3":__('Source 3'),"4":__('Source 4'),"5":__('Source 5'),"6":__('Source 6'),"7":__('Source 7'),"8":__('Source 8'),"9":__('Source 9'),"10":__('Source 10'),"11":__('Source 11')}, formatter: Table.api.formatter.normal},
                        // {field: 'task_id', title: __('Task_id')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});